$(function() {
	admin.drawBase.init();
});
Namespace('admin.drawBase', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	detail:function(id) {
		if (id != null) {
			top.addTab(id,'详情', contextPath+'/draw/base/detail?id=' + id);
		}
	},
	down: function (id) {
		var tip = "确定停止吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/draw/base/down';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					var pageopt = $('#datagrid').datagrid('getPager').data("pagination").options;
					console.log(pageopt.pageNumber);
                    admin.drawBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	up: function (id) {
		var tip = "确定开启吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/draw/base/up';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					var pageopt = $('#datagrid').datagrid('getPager').data("pagination").options;
					console.log(pageopt.pageNumber);
                    admin.drawBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	toAdd:function() {
		top.addTab("1",'添加', contextPath+'/draw/base/toAdd');
	},
	toUpdate:function(id) {
		if (id != null) {
			top.addTab(id,'编辑', contextPath+'/draw/base/toUpdate?id=' + id);
		}
	},
	update: function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/draw/base/update';
        $('#datagrid').datagrid('loading');
		$.post(url, data, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('编辑成功');
				top.addTab("1",'抽奖列表', contextPath+'/draw/base/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	add: function () {
		 	if(!$('#data-form').form('validate')) return;
	        var data=$('#data-form').form('jsonObject');
            var url = contextPath + '/draw/base/create';
			$.post(url, data, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('创建成功');
					top.addTab("",'抽奖列表', contextPath+'/draw/base/list');
				} else {
					top.showInfo(result.msg);
				}
			});
	},
});